package com.ly.web.controller.erp;

import java.util.List;

import com.ly.heart.domain.dto.KingProcureRefundQueryDto;
import com.ly.heart.domain.vo.select.query.KingProcureRefundSelectQueryDto;
import com.ly.heart.service.IKingProcureRefundService;
import com.ly.heart.service.king.KingProcureRefundPushService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.KingProcureRefundEntity;
import com.ly.common.utils.poi.ExcelUtil;

import javax.annotation.Resource;

/**
 * 金蝶-采购退料单Controller
 *
 * @author cxl
 * @date 2024-07-16
 */
@Api(value = "金蝶-采购退料单", tags = "金蝶-采购退料单")
@RestController
@RequestMapping("/heart/KingProcureRefund")
public class KingProcureRefundController extends BaseController {

    @Resource
    private IKingProcureRefundService kingProcureRefundService;
    @Resource
    private KingProcureRefundPushService kingProcureRefundPushService;


    @PreAuthorize("@ss.hasPermi('heart:KingProcureRefund:add')")
    @Log(title = "暂存采购退料单", businessType = BusinessType.INSERT)
    @PostMapping("/draft")
    @ApiOperation("暂存采购退料单")
    public  AjaxResult draft(@RequestBody KingProcureRefundEntity kingProcureRefund){
        return kingProcureRefundService.draft(kingProcureRefund);
    }

    @PreAuthorize("@ss.hasPermi('heart:KingProcureRefund:add')")
    @Log(title = "提交采购退料单", businessType = BusinessType.INSERT)
    @PostMapping("/submit")
    @ApiOperation("提交采购退料单")
    public AjaxResult submit(@RequestBody KingProcureRefundEntity kingProcureRefund){
        return kingProcureRefundService.submit(kingProcureRefund);
    }

    @PreAuthorize("@ss.hasPermi('heart:KingProcureRefund:edit')")
    @Log(title = "修改采购退料单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation("修改采购退料单")
    public AjaxResult update(@RequestBody KingProcureRefundEntity kingProcureRefund){
        return kingProcureRefundService.update(kingProcureRefund);
    }

    @PostMapping("/list")
    @ApiOperation("查询采购退料单列表")
    public AjaxResult getKingProcureRefundPageListByMaterial(@RequestBody KingProcureRefundQueryDto queryDto){
        return kingProcureRefundService.getKingProcureRefundPageListByMaterial(queryDto);
    }

    @PostMapping("/select")
    @ApiOperation("采购退料单选单接口")
    public AjaxResult getKingProcureRefundSelect(@RequestBody KingProcureRefundSelectQueryDto queryDto){
        return kingProcureRefundService.getKingProcureRefundSelect(queryDto);
    }

    @PreAuthorize("@ss.hasPermi('heart:KingProcureRefund:export')")
    @Log(title = "采购退料单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出采购退料单列表")
    public AjaxResult export(KingProcureRefundEntity kingProcureRefundEntity)
    {
        List<KingProcureRefundEntity> list = kingProcureRefundService.selectKingProcureRefundEntityList(kingProcureRefundEntity);
        ExcelUtil<KingProcureRefundEntity> util = new ExcelUtil<KingProcureRefundEntity>(KingProcureRefundEntity.class);
        return util.exportExcel(list, "KingProcureRefund");
    }

    @PreAuthorize("@ss.hasPermi('heart:KingProcureRefund:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取采购退料单详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(kingProcureRefundService.selectKingProcureRefundEntityById(id));
    }

    @PreAuthorize("@ss.hasPermi('heart:KingProcureRefund:remove')")
    @Log(title = "采购退料单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除采购退料单")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(kingProcureRefundService.deleteKingProcureRefundEntityByIds(ids));
    }

    @GetMapping ("/push/{procureRefundId}")
    @ApiOperation ("采购退料单推送")
    public AjaxResult push(@PathVariable String procureRefundId){
        kingProcureRefundPushService.push(procureRefundId);
        return AjaxResult.success("推送成功！");
    }


}
